Hongyu's tutorial about Python in earth science!

Hi This is Hongyu's tutorial about Python in earch science!

I know there are numerous tutorials out there, but I would like to make this more project based thus help us copy and paste a little bit easier.

How to read this document ?

There are 2 types words in this tutorial.

  1. if you saw words like the following, this is for explaining what is going on

I am the words explaining things !

  1. if you saw words like the following, this is the code that you could copy and paste

copy me and paste somewhere else !

Any questions or typos in this tutorial ?

Please feel free to send me an email !

My email address is hongyu.xiao@hotmail.com


Tools needed for this tutorials

Anaconda / Jupyter Notebook / Pandas&Numpy / Matplotlib

  • Anaconda: this is used to install modules and packages in python

  • Jupyter Notebook: this is used to establish an interactive environment when coding and debugging

  • Pandas&Numpy: this is used to mutipulate the formatted data

  • Matplotlib: this is used for plotting out the data

Install Anaconda

Here is a very good information page on installing anaconda

Without digging into what Anaconda is, we just need to go to Anaconda Installation Document page, and install anaconda following the steps there.

Please be aware that you will need to download corresponding file based on your system (MacOs/Windows/Linux)

Verify your Anaconda installation

After your installation, you could verify your installation. Detailed instruction is listed on https://docs.anaconda.com/anaconda/install/verify-install/

Now, I suppose you have installed anaconda and you simple click the anaconda prompt and it will open a commend line interface.

It shows information like the following:

(base) C:\Users\Hongyu>

The most important indicator is (base), if you see that then you are ready to go !

Install Jupyter Notebook

Open anaconda prompt, and then type the following

conda create --name Data_Analysis python=3

And then you will see the following content

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\Hongyu\Anaconda3\envs\PKP

  added / updated specs:
    - python=3

The following NEW packages will be INSTALLED:

  ca-certificates    conda-forge/win-64::ca-certificates-2020.4.5.1-hecc5488_0
  certifi            conda-forge/win-64::certifi-2020.4.5.1-py38h32f6830_0
  openssl            conda-forge/win-64::openssl-1.1.1g-he774522_0
  pip                conda-forge/noarch::pip-20.1-pyh9f0ad1d_0
  python             conda-forge/win-64::python-3.8.2-h5fd99cc_7_cpython
  python_abi         conda-forge/win-64::python_abi-3.8-1_cp38
  setuptools         conda-forge/win-64::setuptools-46.4.0-py38h32f6830_0
  sqlite             conda-forge/win-64::sqlite-3.30.1-hfa6e2cd_0
  vc                 conda-forge/win-64::vc-14.1-h869be7e_1
  vs2015_runtime     conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
  wheel              conda-forge/noarch::wheel-0.34.2-py_1
  wincertstore       conda-forge/win-64::wincertstore-0.2-py38_1003

Proceed ([y]/n)?

Type

y

Great, now you have create your own data analysis environment for python ! Next is to install jupyter notebook in this environment!

conda activate Data_Analysis

conda install jupyterlab

and type

y

Install Pandas&Numpy

Open anaconda prompt, and type the flowing command to activate your python environment

conda activate Data_Analysis

Then type the flowing

conda install pandas

conda install numpy

If you see any confirmation question, simply type

y

Install Matplotlib

Open anaconda prompt, and type the flowing command to activate your python environment

conda activate Data_Analysis

Then type the flowing

conda install matplotlib

If you see any confirmation question, simply type

y

Install any module you might need for your program

Open anaconda prompt, and type the flowing command to activate your python environment

conda activate Data_Analysis

If the module you need is called I_am_the_module_in_need , just type

conda install I_am_the_module_in_need

If you see any confirmation question, simply type

y